define(["jquery","servers"], function ($,servers) {
    return Backbone.Model.extend({
        defaults: function () {
            return {};
        },
        getInfo:function(){
            var self = this;
            servers.account.info(function(res){
                if(res.success){
                    var menu={};
                    for(var i=0;i<res.data.authorize.length;i++){
                        var temp=res.data.authorize[i].split(":");
                        var page=temp[0]+":"+temp[1];
                        if(!menu.hasOwnProperty(page)){menu[page]="1"}
                    }
                    res.data.pageMenus=$.ExtCommon.getArrByJson(menu);
                }else{
                    res.data={}
                }
                self.set({dataAccountInfo:res});
                self.trigger('bind:Info');
            });
        },
        login:function(json){
            var self = this;
            var data=$.ExtCommon.getMappingJson(json, {"username":"userName","password":"passWord"});
            servers.account.login(data,function(res){
                self.set({dataLogin:res});
                self.trigger('login:Info');
            });
        },
        checkLogin:function(){
            var self = this;
            servers.account.check(function(res){
                self.set({dataCheckLogin:res});
                self.trigger('check:Login');
            });
        },
        logout:function(){
            var self = this;
            servers.account.logout(function(res){
                self.set({dataLogout:res});
                self.trigger('logout:Info');
            });
        },
        updPwd:function (json) {
            var self = this;
            var data= $.ExtCommon.getMappingJson(json,{oldPassword:"old",password:"new",repeatPassword:"again"});
            servers.account.pwd(data,function(res){
                self.set({dataPwd:{req:json,res:res}});
                self.trigger('save:Pwd');
            });
        },
        getPagePower:function(page){
            var self = this;
            var arr=page.split(":");
            if(arr.length===2){
                servers.account.pagePower({resource:arr[0],permission:arr[1]},function(res){
                    self.set({dataPagePower:{req:{page:page},res:res}});
                    self.trigger('bind:PagePower');
                });
            }
        }
    });
});